Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

199
Vistas
How to get "property missing" error messages with empty (and thus unsealed) objects

So, I have an API that takes an options object, something like this:

type Options = { pos: number };

function doTheThing(options: Options) {
}

Now, if I call this with any of the below, I get a nice error message:

doTheThing(); // requires another argument.
doTheThing({ something: 20 }); // missing property "pos"

Great. But if I pass an empty object, Flow will consider this "unsealed" and thus have no issue with it:

doTheThing({ }); // No error, would like it to say "pos" missing instead.

So, I tried making it exact:

type Options = {| pos: number |};

Now, I get an error, but it's not very nice:

doTheThing({ }); //  Cannot call `doTheThing` with object literal bound to `options` because inexact object literal [1] is incompatible with exact `Options` [2].

But I just want it to say "pos" is missing. The above is more complicated and just forces you to have to read the definition of Options in order to know what it takes. I want it to offer the actual missing property to you. Which it will do, as soon as I put any random thing in there:

doTheThing({ x: 10 }); //  Cannot call `doTheThing` with object literal bound to `options` because property `pos` is missing in object literal [1] but exists in `Options` 

Is there any way to get it to give me that error message on {}, instead of the less useful message? Ideally through some sort of extra annotation on the type and not some global flow configuration that like turns off unsealed objects or something.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda